<?php $this->load->view('home/layout/header') ?>
<header class="my-head flex">
    <div class="my-return">
        <a href="<?php echo site_url('home/ucenter/baseInfoSet'); ?>">
            <i class="iconfont icon-zuojiantou"></i>
        </a>
    </div>
    <div class="my-name">账户切换</div>
</header>
<section class="my-text widthMax">
    <ul class="my-list">
        <?php foreach ($userRelated as $key=>$user) :?>
            <li <?php if ($key === 0) :?>class="active"<?php endif;?> data-user="<?php echo $user['uid'] ?>">
                <a href="javascript:;" class="flex">
                    <div class="my-photo flex">
                        <div class="photo-img">
                            <img src="<?php echo $user['personalPhoto'] ? $user['personalPhoto'] : '/skins/common/images/photo0.jpg'; ;?>">
                        </div>
                        <div class="flex-1"><?php echo $user['userName'] ?></div>
                    </div>
                    <div class="my-photo flex">
                        <div class="photo-text flex-1"><?php echo $user['userTypeName'] ?></div>
                        <i class="dian"></i>
                    </div>
                </a>
            </li>
        <?php endforeach;?>
    </ul>
    <a href="<?php echo site_url('login/index/logout').'?from=userCheck';?>" class="my-pass flex">
        <p class="flex-1">换个新账号登录</p>
        <i class="iconfont icon-youjiantou"></i>
    </a>
</section>
<?php $this->load->view('home/layout/footer') ?>
<div class="alert-confirm am-modal am-modal-confirm" tabindex="-1" id="switch">
    <div class="am-modal-dialog">
        <div class="am-modal-bd">您确定要切换账户吗？</div>
        <div class="am-modal-footer">
          <span class="am-modal-btn" data-am-modal-cancel>取消</span>
          <span class="am-modal-btn" data-am-modal-confirm>确定</span>
        </div>
    </div>
</div>
<script type="text/javascript">
$(function(){
    $('.my-text').on('click','.my-list li:not([class=active])',function(e){
        $this = $(this);
        $('#switch').modal({
            relatedTarget: this,
            onConfirm: function(options){
                var userUid = $(this.relatedTarget).data('user');
                $.ajax({
                    type: 'get',
                    dataType: 'jsonp',
                    jsonCallback: 'jsonCallback',
                    data : {uid : userUid},
                    url: '<?php echo site_url('login/index/userSwitchLogin') ?>,
                    success: function (json) {
                        if (json.status) {
                            //$this.addClass('active').siblings().removeClass('active');
                            window.location.href = json.msg;
                        } else {
                            alert(json.msg);
                        }
                    }
                });
            }
        });
    });
});
</script>
